<?php
// +----------------------------------------------------------------------
// | flow-notify / Ximi.php    [ 2021/11/9 4:58 下午 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2011~2021 zhangqiquan All rights reserved.
// +----------------------------------------------------------------------
// | Author: zhangqiquan <768617998@qq.com>
// +----------------------------------------------------------------------
declare (strict_types=1);

namespace notify\apppush;

use notify\apppush\xiaomi\Builder;
use notify\apppush\xiaomi\Constants;
use notify\apppush\xiaomi\Sender;
use notify\Service;

class Xiaomi extends Service
{
    public function __construct(){
    }

    public function send(){
        $secret = 'p9+4HkYmWfQku3WzjCKq0A==';
        $package = 'cn.flownow.www';

        // 常量设置必须在new Sender()方法之前调用
        Constants::setPackage($package);
        Constants::setSecret($secret);

        $sender = new Sender();
        $payload = '{"test":1,"ok":"It\'s a string"}';

// message1 演示自定义的点击行为
        $message1 = new Builder();
        $message1->title('title');  // 通知栏的title
        $message1->description('desc'); // 通知栏的description
        $message1->passThrough(0);  // 这是一条通知栏消息，如果需要透传，把这个参数设置成1,同时去掉title和descption两个参数
        $message1->payload($payload); // 携带的数据，点击后将会通过客户端的receiver中的onReceiveMessage方法传入。
        $message1->extra(Builder::notifyForeground, 1); // 应用在前台是否展示通知，如果不希望应用在前台时候弹出通知，则设置这个参数为0
        $message1->notifyId(2); // 通知类型。同样的类型的通知会互相覆盖，不同类型可以在通知栏并存
        $message1->build();

// 打印返回结果
        print_r($sender->send($message1, 'regId')->getRaw());
    }
}